package com.baidu.baidumap;

import android.os.Bundle;
import android.widget.Toast;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.overlayutil.DrivingRouteOverlay;
import com.baidu.mapapi.overlayutil.WalkingRouteOverlay;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.route.DrivingRoutePlanOption;
import com.baidu.mapapi.search.route.DrivingRouteResult;
import com.baidu.mapapi.search.route.OnGetRoutePlanResultListener;
import com.baidu.mapapi.search.route.PlanNode;
import com.baidu.mapapi.search.route.RoutePlanSearch;
import com.baidu.mapapi.search.route.TransitRouteResult;
import com.baidu.mapapi.search.route.WalkingRoutePlanOption;
import com.baidu.mapapi.search.route.WalkingRouteResult;

import java.util.ArrayList;
import java.util.List;

/**\
 * 步行路线
 */

public class WalkingRouteOverlayDemo extends BaseActivity {
    private RoutePlanSearch routePlanSearch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        search();

    }

    private void search() {
        routePlanSearch = RoutePlanSearch.newInstance();
        routePlanSearch.setOnGetRoutePlanResultListener( new MyListener());

        WalkingRoutePlanOption walkOption = new WalkingRoutePlanOption();
        PlanNode from = PlanNode.withLocation(hmPos);// 创建起点
        PlanNode to = PlanNode.withLocation(new LatLng(40.065796,116.349868));// 创建终点
        walkOption.from(from);
        walkOption.to(to);
        routePlanSearch.walkingSearch(walkOption);

    }
    class MyListener implements OnGetRoutePlanResultListener{


        @Override
        public void onGetWalkingRouteResult(WalkingRouteResult walkingRouteResult) {
            if (walkingRouteResult==null|| SearchResult.ERRORNO.RESULT_NOT_FOUND==walkingRouteResult.error){
                Toast.makeText(getApplicationContext(),"未搜索到结果",Toast.LENGTH_SHORT).show();
                return;
            }
            WalkingRouteOverlay overlay = new WalkingRouteOverlay(baiduMap);
            baiduMap.setOnMarkerClickListener(overlay);
            overlay.setData(walkingRouteResult.getRouteLines().get(0));
            overlay.addToMap();
            overlay.zoomToSpan();

        }

        @Override
        public void onGetTransitRouteResult(TransitRouteResult transitRouteResult) {

        }

        @Override
        public void onGetDrivingRouteResult(DrivingRouteResult drivingRouteResult) {

        }
    }


}
